package cn.itsource.exception;

import cn.itsource.result.JSONResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice//控制类增强类
public class GlobalExceptionHandler {
    @ExceptionHandler(MyException.class)//捕获异常类
    public JSONResult MyException(MyException e){
        return JSONResult.error(e.getMessage());
    }
    @ExceptionHandler(ArithmeticException.class)//捕获异常类
    public JSONResult arithmeticException(ArithmeticException e){
        return JSONResult.error("算术异常");
    }
    @ExceptionHandler(Exception.class)//捕获异常类兜底
    public JSONResult exception(Exception e){
        return JSONResult.error("系统异常");
    }
}
